package com.app.system.common;

import com.app.business.model.Parameter;
import com.app.business.model.ZsProject;
import com.app.business.service.ParameterService;
import com.app.business.service.ZsProjectService;
import com.app.system.permission.model.DataDict;
import com.app.system.permission.service.DataDictService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by wcf-pc on 2018/12/10.
 */
@RestController
public class ModulesController {

    @Autowired
    private DataDictService dataDictService;
    @Autowired
    private ZsProjectService zsProjectService;
    @Autowired
    private ParameterService parameterService;

    @RequestMapping(value = "/dataDict/{parentName}", produces = "application/json;charset=UTF-8")
    public List dataDictList(@PathVariable("parentName") String parentName) {
        List<DataDict> dataDictList = this.dataDictService.findListByParentName(parentName);
        List<Map> dataList = Lists.newLinkedList();
        if (!CollectionUtils.isEmpty(dataDictList)) {
            for (DataDict dataDict : dataDictList) {
                Map map = Maps.newHashMap();
                map.put("name", dataDict.getName());
                map.put("value", dataDict.getValue());
                map.put("color", dataDict.getColor());
                dataList.add(map);
            }
        }
        return dataList;
    }


    /**
     * 从数据库获取征收项目集合，用于前台select处理
     *
     * @return
     */
    @RequestMapping(value = "/zsProjectList", produces = "application/json;charset=UTF-8")
    public List zsProjectList() {
        List<ZsProject> zsProjectList = this.zsProjectService.zsProjectList();
        return zsProjectList;
    }

    /**
     * 从数据库获取参数配置集合，用于前台select处理
     *
     * @return
     */
    @RequestMapping(value = "/parameterList", produces = "application/json;charset=UTF-8")
    public List parameterList() {
        List<Parameter> parameterList = this.parameterService.parameterList();
        return parameterList;
    }
}
